﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class 异常_AlertException : BasePage
{ 
    protected void Page_Load(object sender, EventArgs e)
    {
        base.ThrowException((Control)this.Page, new AlertException("这个是抛出的异常"));
    }
}


public class BasePage : System.Web.UI.Page, IThrowException
{
    public void ThrowException(Control ct,AlertException EX)
    {
        try
        {
            throw EX;
        }
        catch (Exception e)
        {
            Alert(ct, e.Message);
        }
    }


    public void ThrowException(Control ct, Exception EX)
    {
        try
        {
            throw EX;
        }
        catch (Exception e)
        {
            Alert(ct, e.Message);
        }
    }
 
    public  void Alert(Control control, string message)
    {
        message = message.Replace('\r', '\t').Replace('\n', '\t');
        message = "alert(\"" + message + "\");";
        ScriptManager.RegisterClientScriptBlock(control, typeof(Control), "MyUpdatePanelMessage", message, true);
    }
}


public interface IThrowException
{
    void ThrowException(Control ct, AlertException EX);
    void ThrowException(Control ct, Exception EX);
}



public class AlertException : Exception
{
    public AlertException(){}
    public AlertException(string message): base(message){}
}

